home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 001a / tm301_2.zip / TOOLBOX3.SCR < prev    next >
Text File  |  1992-01-03  |  12KB  |  403 lines

  1. ;
  2. ; TOOLBOX3.SCR (c) Copyright 1990-1992 by White River Software.
  3. ; All right reserved.
  4. ;
  5. ; Date written: 10 May 1990
  6. ; Revision:      1 Jan 1992
  7. ;
  8. ;
  9. ; This toolbox defines several procedures to access the phone
  10. ; directory and two procedures to calcuate the difference between
  11. ; two date/time strings.
  12. ;
  13. ; To use this toolbox, you should add the line
  14. ;    #include "toolbox3.scr"
  15. ; at the beginning of your script file.  This will increase the file
  16. ; size of the compiled script file .TMS by about 6K.  To minimum the
  17. ; overhead, you should cut and paste the procedures that you used into
  18. ; your script file.  For example, the <DiffTime> and <DiffDate>
  19. ; procedures may be excluded.
  20. ;
  21. ; The <PhoneDirectory> variable tells the Phone's procedures which
  22. ; phone directory is to be access.  Default is the TM.FON.
  23. ;
  24. ; Summary:
  25. ;
  26. ;   PhoneSize size
  27. ;   ; return the number of entries in the phone directory
  28. ;
  29. ;   PhoneFind name,number,startPoint
  30. ;   ; find an entry by <name> and return the entry number in <number>
  31. ;   ; starting from <startPoint>
  32. ;
  33. ;   PhoneRead number,name,password,linkscript,logfile,phone,total,last
  34. ;   ; read the <number>-th entry of <PhoneDirectory>
  35. ;   ; <total> is an integer variable
  36. ;
  37. ;   PhoneWrite number,name,linkscript,logfile,password,phone,total,last
  38. ;   ; write the <number>-th entry of <PhoneDirectory>
  39. ;   ; <total> is an integer
  40. ;
  41. ;   ConvertDate format1,date1,format1,date2
  42. ;   ; convert the date string <date1> of format <format1> to
  43. ;   ; <date2> of <format2>
  44. ;
  45. ;   DiffDate date1,date2,days
  46. ;   ; <days> = <date2> - <date1>
  47. ;
  48. ;   DiffTime time1,time2,seconds
  49. ;   ; <seconds> = <time2> - <time1>
  50. ;
  51.  
  52. string PhoneDirectory
  53.  
  54. PhoneDirectory = "TM.FON"     ; phone directory to be accessed by
  55.                               ; the following procedures
  56.  
  57.  
  58. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  59. ;
  60. ; PhoneSize size
  61. ; function: calcuate the number of entires in the phone directory
  62. ;           <PhoneDirectory>
  63. ;
  64. Procedure PhoneSize integer size
  65. filesize PhoneDirectory,size
  66. size = size / 131             ; each entry is 131 bytes
  67. EndProc
  68.  
  69.  
  70. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  71. ;
  72. ; PhoneFind name,number,startPoint
  73. ; function: find an entry by <name> and return the entry number in <number>
  74. ;           starting from <startPoint>
  75. ; remark:   <number> is set to 0 if <name> is not found
  76. ;           <success> is FALSE if the phone directory cannot be open
  77. ;           To find from the beginning of the phone directory, use
  78. ;               PhoneFind name,number,1
  79. ;           To continue the search, use
  80. ;               PhoneFind name,number,number+1
  81. ; caution:  this function will close the formly opened file since the
  82. ;           OPEN command is used.  You should close the file before
  83. ;           issuing this command and reopen the file after this command
  84. ;
  85. Procedure PhoneFind string name,integer number,startPoint
  86. string entry
  87. integer pos,size
  88. PhoneSize size
  89. if startPoint>size            ; no more entries
  90.    number = 0                 ; report as not found
  91.    return
  92. endif
  93. number = startPoint-1
  94. if number<0
  95.    number = 0
  96. endif
  97. pos = 0
  98. open PhoneDirectory
  99. if success
  100.    seek number*131
  101.    While success and pos=0 and number<size
  102.       number = number+1
  103.       read entry                 ; read a phone entry
  104.       if success
  105.          strpos entry,name,pos   ; search for <name>
  106.          if pos>30
  107.             pos = 0              ; not in name field
  108.          endif
  109.       endif
  110.    EndWhile
  111.    close
  112. endif
  113. if pos=0
  114.    number = 0                 ; set <number> to 0 if not found
  115. endif
  116. EndProc
  117.  
  118.  
  119. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  120. ;
  121. ; PhoneRead number,name,password,linkscript,logfile,phone,total,last
  122. ; function: read the <number>-th entry of <PhoneDirectory>
  123. ; remark:   <success> is FALSE if the phone directory cannot be open
  124. ;           tailing spaces in each field are discarded
  125. ;           <total> is an integer variable, the others are string
  126. ;           variables
  127. ; caution:  this function will close the formly opened file since the
  128. ;           OPEN command is used.  You should close the file before
  129. ;           issuing this command and reopen the file after this command
  130. ;
  131. Procedure PhoneRead integer number,string name,password,linkscript,logfile,phone,integer total,string last
  132. string entry,totalstr
  133. integer size
  134.  
  135.    Procedure GetField string field,integer FieldLength,FieldOffset
  136.    integer len,orglen
  137.    string ch
  138.    substr entry,FieldOffset+1,FieldLength,field ; get the field
  139.    len = FieldLength
  140.    orglen = FieldLength       ; delete tailing space
  141.    ch = " "
  142.    While len>0 and ch=" "
  143.       substr field,len,1,ch
  144.       if ch=" "
  145.          len = len-1
  146.       endif
  147.    EndWhile
  148.    if orglen>len
  149.       strdel field,len+1,orglen-len
  150.    endif
  151.    EndProc
  152.  
  153. PhoneSize size
  154. open PhoneDirectory
  155. if success
  156.    if number<1
  157.       seek 0
  158.    elseif number>size
  159.       seek (size-1)*131
  160.    else
  161.       seek (number-1)*131     ; each entry is 131 bytes
  162.    endif
  163.    read entry
  164.    GetField name,30,0
  165.    GetField password,15,30
  166.    GetField linkscript,8,46
  167.    GetField logfile,8,55
  168.    GetField phone,20,64
  169.    GetField totalstr,5,96
  170.    atoi  totalstr,total
  171.    GetField last,8,103
  172.    close
  173. endif
  174. EndProc
  175.  
  176.  
  177. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  178. ;
  179. ; PhoneWrite number,name,linkscript,logfile,password,phone,total,last
  180. ; function: write the <number>-th entry of <PhoneDirectory>
  181. ; remark:   <success> is FALSE if the phone directory cannot be open
  182. ;           <total> is an integer, the others are strings
  183. ;           To change only a field of the entry, you should use the
  184. ;           PhoneRead procedure to read the other fields of the entry,
  185. ;           otherwise, the other fields will be erased.
  186. ; caution:  this function will close the formly opened file since the
  187. ;           OPEN command is used.  You should close the file before
  188. ;           issuing this command and reopen the file after this command
  189. ;
  190. Procedure PhoneWrite integer number,string name,password,linkscript,logfile,phone,integer total,string last
  191. integer EntryPos,size
  192.  
  193.    Procedure WriteField string field,integer FieldLength,FieldOffset,LeftJustify
  194.    integer len
  195.    string space
  196.    seek EntryPos+FieldOffset
  197.    length field,len
  198.    if len>FieldLength
  199.       strdel field,len+1,FieldLength-len
  200.    endif
  201.    if not LeftJustify and len<FieldLength
  202.       strset space," ",1,FieldLength-len
  203.       write space,
  204.    endif
  205.    write field,
  206.    if LeftJustfiy and len<FieldLength
  207.       strset space," ",1,FieldLength-len
  208.       write space,
  209.    endif
  210.    EndProc
  211.  
  212. PhoneSize size
  213. if number<1
  214.    EntryPos = 0
  215. elseif number>size
  216.    EntryPos = (size-1)*131
  217. else
  218.    EntryPos = (number-1)*131
  219. endif
  220. open PhoneDirectory
  221. if success
  222.    WriteField name,30,0,1
  223.    WriteField password,15,30,1
  224.    WriteField linkscript,8,46,1
  225.    WriteField logfile,8,55,1
  226.    WriteField phone,20,64,1
  227.    itoa  total,totalstr
  228.    WriteField totalstr,5,96,0
  229.    WriteField last,8,103,1
  230. endif
  231. close
  232. EndProc
  233.  
  234.  
  235. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  236. ;
  237. ; ConvertDate format1,date1,format2,date2
  238. ; function: convert the date string <date1> of format <format1> to
  239. ;           <date2> of <format2>
  240. ;
  241. Procedure ConvertDate integer format1,string date1,integer format2,string date2
  242. string mm,dd,yy,separator,ch
  243. integer len
  244. length date1,len
  245. date2 = date1
  246. if format1<>format2 and len=8 and format1<=8 and format2<=8
  247.   switch format2        
  248.     case 0,1,2: separator = "-"         ; determine which separator
  249.     case 3,4,5: separator = "/"
  250.     case 6,7,8: separator = "."
  251.   endswitch
  252.   switch format1                        ; extract mm,dd,yy from date1
  253.     case 0,3,6: substr date1,1,2,mm
  254.                 substr date1,4,2,dd
  255.                 substr date1,7,2,yy
  256.     case 1,4,7: substr date1,1,2,dd
  257.                 substr date1,4,2,mm
  258.                 substr date1,7,2,yy
  259.     case 2,5,8: substr date1,1,2,yy
  260.                 substr date1,4,2,mm
  261.                 substr date1,7,2,dd
  262.   endswitch
  263.   substr mm,1,1,ch                      ; set " 1" to "01", etc
  264.   if ch=" "
  265.      strset mm,"0",1,1
  266.   endif
  267.   substr dd,1,1,ch
  268.   if ch=" "
  269.      strset dd,"0",1,1
  270.   endif
  271.   substr yy,1,1,ch
  272.   if ch=" "
  273.      strset yy,"0",1,1
  274.   endif
  275.   switch format2                        ; form the date string
  276.     case 0,3,6: date2 = mm
  277.                 concat date2,separator
  278.                 concat date2,dd
  279.                 concat date2,separator
  280.                 concat date2,yy
  281.     case 1,4,7: date2 = dd
  282.                 concat date2,separator
  283.                 concat date2,mm
  284.                 concat date2,separator
  285.                 concat date2,yy
  286.     case 2,5,8: date2 = yy
  287.                 concat date2,separator
  288.                 concat date2,mm
  289.                 concat date2,separator
  290.                 concat date2,dd
  291.   endswitch
  292.   substr date2,1,1,ch                   ; set "01-01-01" to " 1-01-01"
  293.   if ch="0"
  294.     strset date2," ",1,1
  295.   endif
  296. endif
  297. EndProc
  298.  
  299.  
  300. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  301. ;
  302. ; DiffDate date1,date2,days
  303. ; function: calcuate the number of days between <date1> and <date2>
  304. ;           as if <days>=<date2>-<date1>
  305. ; remark:   <date1> and <date2> in MM-DD-YY format
  306. ;           if <date2> is less then <date1>, it is assumed that <date2>
  307. ;           pass a century
  308. ;           <days> is always a non-negative integer
  309. ;
  310. Procedure DiffDate string date1,date2,integer days
  311.  
  312.    ; calcuate the elapsed days from 1st Jan 1800
  313.    Procedure CalcDays string dateStr,integer days
  314.    string yy,mm,dd
  315.    integer y,m,d
  316.    substr dateStr,7,2,yy      ; <dateStr> in MM-DD-YY format
  317.    substr dateStr,1,2,mm
  318.    substr dateStr,4,2,dd
  319.    atoi yy,y
  320.    atoi mm,m
  321.    atoi dd,d
  322.    days = (y+100)*365 + (y+99)/4
  323.    if m>1                     ; January
  324.       days = days + 31
  325.    endif                      ; Febrary
  326.    if m>2
  327.       if y = y/4*4
  328.          days = days + 29
  329.       else
  330.          days = days + 28
  331.       endif
  332.    endif
  333.    if m>3                     ; March
  334.       days = days + 31
  335.    endif
  336.    if m>4                     ; April
  337.       days = days + 30
  338.    endif
  339.    if m>5                     ; May
  340.       days = days + 31
  341.    endif
  342.    if m>6                     ; June
  343.       days = days + 30
  344.    endif
  345.    if m>7                     ; July
  346.       days = days + 31
  347.    endif
  348.    if m>8                     ; August
  349.       days = days + 31
  350.    endif
  351.    if m>9                     ; September
  352.       days = days + 30
  353.    endif
  354.    if m>10                    ; October
  355.       days = days + 31
  356.    endif
  357.    if m>11                    ; November
  358.       days = days + 30
  359.    endif
  360.    days = days + d
  361.    EndProc
  362.  
  363. CalcDays date1,z1             ; calculate elapsed days from 1st Jan 1800
  364. CalcDays date2,z2
  365. days = z2 - z1
  366. if days<0
  367.    days = days + 36500 + 25   ; pass a century
  368. endif
  369. EndProc
  370.  
  371.  
  372. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  373. ;
  374. ; DiffTime time1,time2,seconds
  375. ; function: calcuate the number of seconds between <time1> and <time2>
  376. ;           as if <seconds>=<time2>-<time1>
  377. ; remark:   <time1> and <time2> in HH:MM:SS format
  378. ;           if <time2> is less then <time1>, it is assumed that <time2>
  379. ;           pass mid-night
  380. ;           <seconds> is always a non-negative integer
  381. ;
  382. Procedure DiffTime string time1,time2,integer seconds
  383. integer h1,m1,s1,h2,m2,s2     ; <time1> and <time2> in "HH:MM:SS" format
  384. string hh,mm,ss
  385. substr time1,1,2,hh           ; get hour part
  386. substr time1,4,2,mm           ; get minuate part
  387. substr time1,7,2,ss           ; get second part
  388. atoi hh,h1                    ; convert to integer
  389. atoi mm,m1
  390. atoi ss,s1
  391. substr time2,1,2,hh           ; get hour,minuate and second from <time2>
  392. substr time2,4,2,mm
  393. substr time2,7,2,ss
  394. atoi hh,h2
  395. atoi mm,m2
  396. atoi ss,s2
  397. if h2<h1                      ; <time2> pass mid-night
  398.    h2 = h2 + 24
  399. endif
  400. seconds = (h2-h1)*3600 + (m2-m1)*60 + (s2-s1)
  401. EndProc
  402.  
  403.